package com.mystyle.le.liuxiang.asynctaks;

import android.content.Context;
import android.os.AsyncTask;

import com.mystyle.le.liuxiang.callback.MyCallBack;
import com.mystyle.le.liuxiang.utils.DownData;

/**
 * Created by le on 2016/10/26.
 */
public class MyAsyncTaks extends AsyncTask<String ,Void,String > {
    private MyCallBack.HeadListBack listBack;
    private Context context;

    public MyAsyncTaks(MyCallBack.HeadListBack listBack, Context context) {
        this.listBack = listBack;
        this.context = context;
    }

    @Override
    protected String doInBackground(String... params) {
        //判断是否有网
        if (DownData.isNetWorkConn(context)){
            String param = params[0];
            byte[] bytes = DownData.downData(param);
            if (bytes!=null&&bytes.length>0){
                String s = new String(bytes,0,bytes.length);
                return s;
            }
        }
        return null;
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        if (s!=null){
            listBack.sendBack(s);
        }
    }
}
